package com.df.datacloud.utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by junlee on 2017/10/16.
 */
public class RSASignature {
	private static final Logger logger = LoggerFactory.getLogger(RSASignature.class);
	public static final String key = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCqUddgzZwKzkSuHyo" + "IYW/WnooSjCaQGvRVIa6q+uxgy5arc4epb43EceXjXeJNPq/gLcx/xPRTGkJgeVVmJwPW157rNnoywJ3UqMfpb" + "3eVSjuxY+67CiW49zUvvRyT1Z3LbC0RO422u5014YHlgDlNXb7xug/l6X28/vUBle2o0wIDAQAB";
	
	public static final String tsignData = "IT6d9VOBeWSyBJb1ySQRaMnoplWQgXffVFbjJVbPPYBA+k/qMpYxA3xea5UxaJwxNpjdYHliCqQrrY2oVO10LM0yWexClKBR22Gt+hrgVOlYKP0+WR6nq09OHcZXKNJ5YIOzmU/k9vBWDn5ub1xFc0utpo5JlFyKKINg+vgunyk=";
	
	public static void main(String[] args) throws Exception {
		
		//  mobile = 18811447722 , timestamp=1503913814794 ,partner= boluodai
		
		//String data = "boluodai&18811447722&1503913814794";
		
	//	System.out.println("====" + doCheck(data,tsignData));
	}
	/**
	public static boolean doCheck(String content,String signData) {
		logger.info( "验签开始，content={},key={} ,signData={}",content,key,signData);
		try {
			KeyFactory keyFactory = KeyFactory.getInstance("RSA");
			byte[] encodedKey = Base64.decodeBase64(key);
			PublicKey pubKey = keyFactory.generatePublic(new X509EncodedKeySpec(encodedKey));
			java.security.Signature signature = java.security.Signature.getInstance("SHA1withRSA");
			signature.initVerify(pubKey);
			signature.update(content.getBytes("UTF-8"));
			boolean bverify = signature.verify(Base64.decodeBase64(signData));
			logger.info( "验签结束，content={},key={} ,signData={}，bverify={}",content,key,signData,bverify);
			return bverify;
		} catch (Exception e) {
			
			logger.error("验签失败，e={}" ,e);
		}
		return false;
	}
	
	**/
	
	
}